package com.fumihiko.modules.jxxm.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.fumihiko.modules.jxxm.entity.HonorableEmployeesEntity;
import com.fumihiko.modules.jxxm.entity.RetiredEmployeesEntity;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.fumihiko.modules.jxxm.entity.OldWorkerEntity;
import com.fumihiko.modules.jxxm.service.OldWorkerService;
import com.fumihiko.common.utils.PageUtils;
import com.fumihiko.common.utils.R;



/**
 *
 *
 * @author hanwenpeng
 * @email devilzwy@gmail.com
 * @date 2022-03-30 15:36:34
 */
@RestController
@RequestMapping("jxxm/oldworker")
public class OldWorkerController {
    @Autowired
    private OldWorkerService oldWorkerService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("jxxm:oldworker:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = oldWorkerService.queryPage(params);

        return R.ok().put("page", page);
    }

    /**
     * 条件查询列表
     */
    @RequestMapping("/searchList")
    @RequiresPermissions("jxxm:oldworker:searchList")
    public R searchList(@RequestParam Map<String, Object> params){
        PageUtils page = oldWorkerService.searchPage(params);

        return R.ok().put("page", page);
    }

    /**
     * 退休费错误检查列表
     */
    @RequestMapping("/listError")
    @RequiresPermissions("jxxm:oldworker:listError")
    public R listError(@RequestParam Map<String, Object> params){
        List<OldWorkerEntity> list = oldWorkerService.queryErrorPage(params);

        return R.ok().put("list", list);
    }

    /**
     * 个人编码重复查询
     */
    @RequestMapping("/listRepeat")
    @RequiresPermissions("jxxm:oldworker:listRepeat")
    public R listRepeat(@RequestParam Map<String, Object> params){
        PageUtils page = oldWorkerService.queryRepeatPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 死亡人员列表
     */
    @RequestMapping("/listDeath")
    @RequiresPermissions("jxxm:oldworker:listDeath")
    public R listDeath(@RequestParam Map<String, Object> params){
        PageUtils page = oldWorkerService.queryDeathPage(params);

        return R.ok().put("page", page);
    }

    /**
     * 条件查询死亡人员列表
     */
    @RequestMapping("/searchListDeath")
    @RequiresPermissions("jxxm:oldworker:searchListDeath")
    public R searchListDeath(@RequestParam Map<String, Object> params){
        PageUtils page = oldWorkerService.searchDeathPage(params);

        return R.ok().put("page", page);
    }

    /**
     * 死亡人员导出
     */
    @RequestMapping("/listDeathExcel")
    @RequiresPermissions("jxxm:oldworker:listDeathExcel")
    public R listDeathExcel(@RequestParam Map<String, Object> params){
        List<OldWorkerEntity> list = oldWorkerService.listDeathExcel(params);

        return R.ok().put("list", list);
    }

    /**
     * 删除人员列表
     */
    @RequestMapping("/listDelete")
    @RequiresPermissions("jxxm:oldworker:listDelete")
    public R listDelete(@RequestParam Map<String, Object> params){
        PageUtils page = oldWorkerService.queryDeletePage(params);

        return R.ok().put("page", page);
    }

    /**
     * 条件查询删除人员列表
     */
    @RequestMapping("/searchListDelete")
    @RequiresPermissions("jxxm:oldworker:searchListDelete")
    public R searchListDelete(@RequestParam Map<String, Object> params){
        PageUtils page = oldWorkerService.searchDeletePage(params);

        return R.ok().put("page", page);
    }

    /**
     * 姓名列表
     */
    @RequestMapping("/name/{query}")
    @RequiresPermissions("jxxm:oldworker:name")
    public R name(@PathVariable("query") String query){
        List<OldWorkerEntity> list = oldWorkerService.getName(query);

        return R.ok().put("list", list);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("jxxm:oldworker:info")
    public R info(@PathVariable("id") Long id){
		OldWorkerEntity oldWorker = oldWorkerService.getById(id);

        return R.ok().put("oldWorker", oldWorker);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("jxxm:oldworker:save")
    public R save(@RequestBody OldWorkerEntity oldWorker){
		oldWorkerService.save(oldWorker);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("jxxm:oldworker:update")
    public R update(@RequestBody OldWorkerEntity oldWorker){
		oldWorkerService.updateById(oldWorker);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("jxxm:oldworker:delete")
    public R delete(@RequestBody Long[] ids){
//		oldWorkerService.removeByIds(Arrays.asList(ids));
        oldWorkerService.removeByState(ids);

        return R.ok();
    }

    /**
     * 恢复数据
     */
    @RequestMapping("/recoveryData")
    @RequiresPermissions("jxxm:oldworker:recoveryData")
    public R recoveryData(@RequestBody Long[] ids){
        //retiredEmployeesService.removeByIds(Arrays.asList(ids));
        oldWorkerService.recoveryById(ids);

        return R.ok();
    }


    /**
     * 生活补贴人员导出
     */
    @RequestMapping("/listExcel")
    @RequiresPermissions("jxxm:oldworker:listExcel")
    public R listExcel(@RequestParam Map<String, Object> params){
        List<OldWorkerEntity> list = oldWorkerService.listExcel(params);

        return R.ok().put("list", list);
    }

}
